package com.neusoft.elmboot.service.Impl;

import com.neusoft.elmboot.mapper.BusinessMapper;
import com.neusoft.elmboot.mapper.OrdersMapper;
import com.neusoft.elmboot.po.Business;
import com.neusoft.elmboot.service.BusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;

@Service
public class BusinessServiceImpl implements BusinessService {

    @Autowired
    private BusinessMapper businessMapper;
    
    @Autowired
    private OrdersMapper ordersMapper;
    
    @Override
    public List<Business> listBusinessByOrderTypeId(Integer orderTypeId) {
        return businessMapper.listBusinessByOrderTypeId(orderTypeId);
    }

    @Override
    public List<Business> listAllBusiness(){
        return businessMapper.listAllBusiness();
    }

    @Override
    public Business getBusinessById(Integer businessId) {
        return businessMapper.getBusinessById(businessId);
    }
    
    @Override
    public BigDecimal getAvgMarkById(Integer businessId) {
    	BigDecimal allMark = new BigDecimal(ordersMapper.getAllMarkById(businessId));
    	return allMark.divide(new BigDecimal(ordersMapper.getNumberById(businessId)),2,RoundingMode.HALF_UP);
    }
}
